package com.share.configuration;

import com.share.demo.event.ZookeeperWatcher;
import org.apache.zookeeper.ZooKeeper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * author:caifan
 * date:2019/8/27
 */
@Configuration
@Import({RedisConfiguration.class, WebMvcConfiguration.class})
public class MyConfiguration {

    @Value("${spring.zookeeper.host:127.0.0.1:2181}")
    private String host;

    @Value("${spring.zookeeper.timeout:5000}")
    private int sessionTimeout;

    @Bean
    @ConfigurationProperties(prefix = "spring.zookeeper")
    public ZooKeeper getZookeeper() throws Exception {
        ZooKeeper zooKeeper = new ZooKeeper(host, sessionTimeout, new ZookeeperWatcher());
        return zooKeeper;
    }
}
